package com.sxp.model;

import java.text.DateFormatSymbols;
import java.util.Calendar;

/**
 * Created by dixon on 10/11/14.
 */
public class MonthHandle {
    private static int thisDay;
    private static int thisHour;
    private static int thisMonth;
    private static int nextMonth;
    private static int afterNextMonth;
    private static int thisMonthYear;
    private static int nextMonthYear;
    private static int afterNextMonthYear;
    private static String thisMonthName;
    private static String nextMonthName;
    private static String afterNextMonthName;
    private static int thisMonthDays;
    private static int nextMonthDays;
    private static int afterNextMonthDays;
    private static int thisMonthFirstDay;
    private static int nextMonthFirstDay;
    private static int afterNextMonthFirstDay;

    private static void setMonths() {
        Calendar m1 = Calendar.getInstance();
        Calendar m2 = Calendar.getInstance();
        Calendar m3 = Calendar.getInstance();

        DateFormatSymbols dfs = new DateFormatSymbols();
        String[] months = dfs.getMonths();
        thisMonthYear = m1.get(Calendar.YEAR);
        thisMonth = m1.get(Calendar.MONTH);
        thisDay = m1.get(Calendar.DAY_OF_MONTH);
        thisHour = m1.get(Calendar.HOUR_OF_DAY);

        m1.set(thisMonthYear, thisMonth, 1);
        m2.set(thisMonthYear, thisMonth + 1, 1);
        m3.set(thisMonthYear, thisMonth + 2, 1);

        nextMonthYear = m2.get(Calendar.YEAR);
        afterNextMonthYear = m3.get(Calendar.YEAR);

        nextMonth = m2.get(Calendar.MONTH);
        afterNextMonth = m3.get(Calendar.MONTH);
        thisMonthName = months[thisMonth];
        nextMonthName = months[nextMonth];
        afterNextMonthName = months[afterNextMonth];
        thisMonthDays = m1.getActualMaximum(Calendar.DAY_OF_MONTH);
        nextMonthDays = m2.getActualMaximum(Calendar.DAY_OF_MONTH);
        afterNextMonthDays = m3.getActualMaximum(Calendar.DAY_OF_MONTH);
        thisMonthFirstDay = m1.get(Calendar.DAY_OF_WEEK);
        nextMonthFirstDay = m2.get(Calendar.DAY_OF_WEEK);
        afterNextMonthFirstDay = m3.get(Calendar.DAY_OF_WEEK);

    }

    public static String getHide(int i) {
        setMonths();
        if(i<thisDay){
            return "hide";
        }if((i==thisDay) && (thisHour>=9)){
            return "hide";
        }
        return "nonhide";
    }

    public static int getThisMonth() {
        setMonths();
        return thisMonth;
    }

    public static int getNextMonth() {
        setMonths();
        return nextMonth;
    }

    public static int getAfterNextMonth() {
        setMonths();
        return afterNextMonth;
    }

    public static String getThisMonthName() {
        setMonths();
        return thisMonthName;
    }

    public static String getNextMonthName() {
        setMonths();
        return nextMonthName;
    }

    public static String getAfterNextMonthName() {
        setMonths();
        return afterNextMonthName;
    }

    public static int getThisMonthYear() {
        setMonths();
        return thisMonthYear;
    }

    public static int getAfterNextMonthYear() {
        setMonths();
        return afterNextMonthYear;
    }

    public static int getNextMonthYear() {
        setMonths();
        return nextMonthYear;
    }

    public static int getThisMonthDays() {
        setMonths();
        return thisMonthDays;
    }

    public static int getNextMonthDays() {
        setMonths();
        return nextMonthDays;
    }

    public static int getAfterNextMonthDays() {
        setMonths();
        return afterNextMonthDays;
    }

    public static String getThisMonthDayClass(int i) {
        setMonths();
        if(((thisMonthFirstDay + i - 1) % 7) == 1){
            return "sun";
        }else if(((thisMonthFirstDay + i - 1) % 7) == 0){
            return "sat";
        }
        return "nor";
    }

    public static String getNextMonthDayClass(int i) {
        setMonths();
        if(((nextMonthFirstDay + i - 1) % 7) == 1){
            return "sun";
        }else if(((nextMonthFirstDay + i - 1) % 7) == 0){
            return "sat";
        }
        return "nor";
    }

    public static String getAfterNextMonthDayClass(int i) {
        setMonths();
        if(((afterNextMonthFirstDay + i - 1) % 7) == 1){
            return "sun";
        }else if(((afterNextMonthFirstDay + i - 1) % 7) == 0){
            return "sat";
        }
        return "nor";
    }
}
